<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"><title>ROS1&amp;2之CmakeList.txt与package.xml | MGodmonkeyの世界</title><meta name="keywords" content="ros"><meta name="author" content="MGodmonkey"><meta name="copyright" content="MGodmonkey"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#18171d"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-touch-fullscreen" content="yes"><meta name="apple-mobile-web-app-title" content="ROS1&amp;2之CmakeList.txt与package.xml"><meta name="application-name" content="ROS1&amp;2之CmakeList.txt与package.xml"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="#18171d"><meta property="og:type" content="article"><meta property="og:title" content="ROS1&amp;2之CmakeList.txt与package.xml"><meta property="og:url" content="https://www.mgodmonkey.cn/posts/5d383f12.html"><meta property="og:site_name" content="MGodmonkeyの世界"><meta property="og:description" content="1. CMakeLists.txt与package.xml的作用 在ROS系统的功能包中 要包含 CMakeLists.txt 与 package.xml 文件来编译功能包的内容 CMakeLists.txt原本是Cmake编译系统的规则文件，而Catkin编译系统基本沿用了CMake的编译风格，只"><meta property="og:locale" content="zh-CN"><meta property="og:image" content="https://mybog.s3.bitiful.net/imgs/cover/cover_5.webp?_r_=959f8357-85a7-938e-e8c5-1c0e1441933e"><meta property="article:author" content="MGodmonkey"><meta property="article:tag"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://mybog.s3.bitiful.net/imgs/cover/cover_5.webp?_r_=959f8357-85a7-938e-e8c5-1c0e1441933e"><meta name="description" content="1. CMakeLists.txt与package.xml的作用 在ROS系统的功能包中 要包含 CMakeLists.txt 与 package.xml 文件来编译功能包的内容 CMakeLists.txt原本是Cmake编译系统的规则文件，而Catkin编译系统基本沿用了CMake的编译风格，只"><link rel="shortcut icon" href="https://mybog.s3.bitiful.net/imgs/favicon.ico"><link rel="canonical" href="https://www.mgodmonkey.cn/posts/5d383f12"><link rel="preconnect" href="//cdn.cbd.int"><meta name="google-site-verification" content="xxx"><meta name="baidu-site-verification" content="Sqt9yFIkjZdA89TY"><meta name="msvalidate.01" content="xxx"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.cbd.int/@fortawesome/fontawesome-free@6.4.0/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://cdn.cbd.int/node-snackbar@0.1.16/dist/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://cdn.cbd.int/@fancyapps/ui@5.0.28/dist/fancybox/fancybox.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/anzhiyu-theme-static@1.0.0/swiper/swiper.min.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={linkPageTop:{enable:!0,title:"与数百名博主无限进步",addFriendPlaceholder:"昵称（请勿包含博客等字样）：\n网站地址（要求博客地址，请勿提交个人主页）：\n头像图片url（请提供尽可能清晰的图片）：\n描述：\n站点截图（可选）：\n"},peoplecanvas:void 0,postHeadAiDescription:{enable:!0,gptName:"MGod",mode:"tianli",switchBtn:!1,btnLink:"https://afdian.net/item/886a79d4db6711eda42a52540025c377",randomNum:3,basicWordCount:1e3,key:"72937022917dd1869dad",Referer:"https://www.mgodmonkey.cn/"},diytitle:{enable:!0,leaveTitle:"空巢啦🪹",backTitle:"有蛋了🪺"},LA51:{enable:!0,ck:"K52IQR51E1m8suUy",LingQueMonitorID:"K7A7hMgFTh8JNQPk"},greetingBox:{enable:!0,default:"晚上好👋",list:[{greeting:"晚安😴",startTime:0,endTime:5},{greeting:"早上好鸭👋, 祝你一天好心情！",startTime:6,endTime:9},{greeting:"上午好👋, 状态很好，鼓励一下～",startTime:10,endTime:10},{greeting:"11点多啦, 在坚持一下就吃饭啦～",startTime:11,endTime:11},{greeting:"午安👋, 宝贝",startTime:12,endTime:14},{greeting:"🌈充实的一天辛苦啦！",startTime:14,endTime:18},{greeting:"19点喽, 奖励一顿丰盛的大餐吧🍔。",startTime:19,endTime:19},{greeting:"晚上好👋, 在属于自己的时间好好放松😌~",startTime:20,endTime:24}]},twikooEnvId:"https://twikoo.mgodmonkey.cn/",commentBarrageConfig:{enable:!0,maxBarrage:1,barrageTime:4e3,accessToken:"",mailMd5:""},music_page_default:"nav_music",root:"/",preloader:{source:3},friends_vue_info:void 0,navMusic:!0,mainTone:void 0,authorStatus:{skills:["🤖️ 数码科技爱好者","🔍 分享与热心帮助","🏠 智能家居小能手","🔨 设计开发一条龙","🤝 专修交互与设计","🏃 脚踏实地行动派","🧱 团队小组发动机","💢 壮汉人狠话不多"]},algolia:{appId:"LV9W14O4EO",apiKey:"0fa7b66b1866f423485b93e1e98ceb34",indexName:"hexo",hits:{per_page:6},languages:{input_placeholder:"输入关键词后按下回车查找",hits_empty:"找不到您查询的内容：${query}",hits_stats:"找到 ${hits} 条结果，用时 ${time} 毫秒"}},localSearch:void 0,translate:{defaultEncoding:2,translateDelay:0,msgToTraditionalChinese:"繁",msgToSimplifiedChinese:"简",rightMenuMsgToTraditionalChinese:"转为繁体",rightMenuMsgToSimplifiedChinese:"转为简体"},noticeOutdate:{limitDay:365,position:"top",messagePrev:"It has been",messageNext:"days since the last update, the content of the article may be outdated."},highlight:{plugin:"highlight.js",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:330},copy:{success:"复制成功",error:"复制错误",noSupport:"浏览器不支持"},relativeDate:{homepage:!1,simplehomepage:!1,post:!1},runtime:"天",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{copy:!0,copyrightEbable:!1,limitCount:50,languages:{author:"作者: MGodmonkey",link:"链接: ",source:"来源: MGodmonkeyの世界",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。",copySuccess:"复制成功，复制和转载请标注本文地址"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"你已切换为繁体",cht_to_chs:"你已切换为简体",day_to_night:"你已切换为深色模式",night_to_day:"你已切换为浅色模式",bgLight:"#3b70fc",bgDark:"#1f1f1f",position:"top-center"},source:{justifiedGallery:{js:"https://cdn.cbd.int/flickr-justified-gallery@2.1.2/dist/fjGallery.min.js",css:"https://cdn.cbd.int/flickr-justified-gallery@2.1.2/dist/fjGallery.css"}},isPhotoFigcaption:!1,islazyload:!0,isAnchor:!1,shortcutKey:{enable:!0,delay:100,shiftDelay:200},autoDarkmode:!0}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={configTitle:"MGodmonkeyの世界",title:"ROS1&2之CmakeList.txt与package.xml",postAI:"true",pageFillDescription:"1. CMakeLists.txt与package.xml的作用, 2. 生成CMakeLists.txt, 2.1 ROS1, 2.2 ROS2, 3. CMakeLists.txt编写, 3.1 ROS1, 3.2 ROS2, 4. package.xml编写, 5. 其他–Setup.py的修改与的作用在系统的功能包中要包含与文件来编译功能包的内容原本是编译系统的规则文件而编译系统基本沿用了的编译风格只是针对工程添加了一些宏定义所以在写法上的与的基本一致用命令创建功能包时会自动生成文件已配置了多数编译选项且包含详细的注释只需稍作修改便可编译自己的文件而文件是描述功能包清单的文件包括功能包的名称版本号作者信息许可信息编译依赖和运行依赖等所以非常重要它指定了由源码到目标文件的规则编译系统在工作时首先会找到每个下的然后按照规则来编译构建生成可通过用命令创建功能包这会自动生成和文件的创建工作空间注为创建功能时指定的铱赖为包名也可以先不指定后面在和中手动添加查看一下在目录下自动生成了哪些文件夹和文件通过上面的命令生成的工作空间如下存放的头文件可同时存放或的源文件但一般文件存放在目录中习惯存放的文件需要自己创建注代码和代码不分家可同时存放在同一功能包中可通过如下的命令来创建功能包以及必要的和文件创建工作空间和分别代表和两种代码的功能包和代表包名查看一下在目录下自动生成了哪些文件夹和文件通过以上命令生成的工作空间如下存放的头文件存放的源文件存放的文件注与不同同一功能包内只能同时包含文件或者文件中的一种编写常用的中架构如下视频解析参考中科院软件所机器人操作系统入门入门教程的最低版本号项目名称找到编译需要的其他新加宏打开的的支持新加宏添加自定义文件新加宏添加自定义文件新加宏添加自定义文件新加宏生成不同语言版本的接口新加宏生成当前的配置供依赖本包的其他软件包调用生成库生成可执行二进制文件定义目标文件依赖于其他目标文件确保其他目标已被构建链接新加宏生成测试生成可安装目标需要自己配置的项目一般就下面几种用于设置头文件的相对路径全局路径默认为功能包所在目录功能包的头文件一般放在功能包根目录下的文件夹所以需要此处添加此文件夹还包含编译器默认的其他头文件路径如默认安装路径系统路径等用于设置需要编译的代码和可执行文件第一个参数为期望生成的可执行文件节点名称后面的参数为参与编译的源文件若需要多个代码文件可依次列出空格分隔用于设置链接库有些功需要使用系统或第三方库函数通过该选项可以配置执行文件链接的库文件第一个参数与相同为可执行文件节点名称后面的参数为需要链接的库依次列出空格分隔用于设置依赖有时候需要自定义消息类型消息类型会在编译过程中产生相应语言的代码若编译的可执行文件依赖这些动态生成的代码则需要添加配置自定义数据类型消息服务动作模板参考更多教程参考常用的中架构如下的最低版本号项目名称查找系统中的依赖项依赖于其他目标文件确保其他目标已被构建生成可执行二进制文件生成可安装目标生成功能包自定义消息类型接口示例模板如下修改修改修改添加自定义消息类型需要添加项自定义自定义自定义相较于基于的文件基于的明显简洁很多假设你编写了文件后需要修改的步骤如下链接源代码为你输入节点后执行的名称如前一个为包名后一个则为这里的设置的名称代表具体执行的代码添加依赖项添加下面这两行代码的目的是让编译器编译这个文件当你自定义消息类型时还需要消息类型文件添加自定义消息类型需要添加项下面两项是固定的是用于生成消息依赖包自定义自定义自定义编写的框架如下相较于的语法就简单许多且和的标签语法通用标签定义了功能包中代码编译时所依赖的其他功能包标签定义了功能包中可执行程序运行时所依赖的其他功能包自定义数据类型话题消息服务数据动作数据模板如下中功能包添加自定义消息类型还需添加下面三行固定形式和上面的修改搭配使用不需要其他的修改在功能包中如果添加类似的文件则需要对功能包中的进行如下的修改结构如下节点名功能包名代码文件执行入口函数名一般执行入口函数名都是也就是说代码中一般要有函数通过来执行下的函数如果有多个代码文件都需要一一添加名称不能一样参考学习笔记与知乎详细分析一个文件首飞爱玩机器人的博客博客",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2024-06-18 16:31:53",postMainColor:""}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:(e,t,a)=>{if(0===a)return;const o={value:t,expiry:Date.now()+864e5*a};localStorage.setItem(e,JSON.stringify(o))},get:e=>{const t=localStorage.getItem(e);if(!t)return;const a=JSON.parse(t);if(!(Date.now()>a.expiry))return a.value;localStorage.removeItem(e)}},e.getScript=(e,t={})=>new Promise(((a,o)=>{const c=document.createElement("script");c.src=e,c.async=!0,c.onerror=o,c.onload=c.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(c.onload=c.onreadystatechange=null,a())},Object.keys(t).forEach((e=>{c.setAttribute(e,t[e])})),document.head.appendChild(c)})),e.getCSS=(e,t=!1)=>new Promise(((a,o)=>{const c=document.createElement("link");c.rel="stylesheet",c.href=e,t&&(c.id=t),c.onerror=o,c.onload=c.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(c.onload=c.onreadystatechange=null,a())},document.head.appendChild(c)})),e.activateDarkMode=()=>{document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#18171d")},e.activateLightMode=()=>{document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#f7f9fe")};const t=saveToLocal.get("theme"),a=window.matchMedia("(prefers-color-scheme: dark)").matches,o=window.matchMedia("(prefers-color-scheme: light)").matches,c=window.matchMedia("(prefers-color-scheme: no-preference)").matches,n=!a&&!o&&!c;if(void 0===t){if(o)activateLightMode();else if(a)activateDarkMode();else if(c||n){const e=(new Date).getHours();e<=6||e>=18?activateDarkMode():activateLightMode()}window.matchMedia("(prefers-color-scheme: dark)").addListener((e=>{void 0===saveToLocal.get("theme")&&(e.matches?activateDarkMode():activateLightMode())}))}else"light"===t?activateLightMode():activateDarkMode();const d=saveToLocal.get("aside-status");void 0!==d&&("hide"===d?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})(window)</script><link rel="stylesheet" href="/css/custom.css" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="MGodmonkeyの世界" type="application/atom+xml"></head><body data-type="anzhiyu"><div id="web_bg"></div><div id="an_music_bg"></div><div id="loading-box" onclick="document.getElementById(&quot;loading-box&quot;).classList.add(&quot;loaded&quot;)"><div class="loading-bg"><img class="loading-img nolazyload" alt="加载头像" src="https://mybog.s3.bitiful.net/imgs/head.jpg"><div class="loading-image-dot"></div></div></div><script>const preloader={endLoading:()=>{document.getElementById("loading-box").classList.add("loaded")},initLoading:()=>{document.getElementById("loading-box").classList.remove("loaded")}};window.addEventListener("load",(()=>{preloader.endLoading()})),setTimeout((function(){preloader.endLoading()}),1e4),document.addEventListener("pjax:send",(()=>{preloader.initLoading()})),document.addEventListener("pjax:complete",(()=>{preloader.endLoading()}))</script><link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-theme-static@1.1.10/progress_bar/progress_bar.css"><script async src="https://cdn.cbd.int/pace-js@1.2.4/pace.min.js" data-pace-options="{ &quot;restartOnRequestAfter&quot;:false,&quot;eventLag&quot;:false}"></script><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><div id="nav-group"><span id="blog_name"><div class="back-home-button"><i class="anzhiyufont anzhiyu-icon-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">网页</div><div class="back-menu-list"><a class="back-menu-item" href="https://www.mgodmonkey.cn/" title="博客"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/favicon.ico" alt="博客"><span class="back-menu-item-text">博客</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">AI项目</div><div class="back-menu-list"><a class="back-menu-item" target="_blank" rel="noopener" href="https://chat.mgodmonkey.cn/" title="ChatGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/圣女果.svg" alt="ChatGPT"><span class="back-menu-item-text">ChatGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://newchat.mgodmonkey.cn/" title="NewChatGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/苹果.svg" alt="NewChatGPT"><span class="back-menu-item-text">NewChatGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://autogpt.mgodmonkey.cn/" title="AutoGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/火龙果.svg" alt="AutoGPT"><span class="back-menu-item-text">AutoGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://academic.chatwithpaper.org/" title="AcademicGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/石榴.svg" alt="AcademicGPT"><span class="back-menu-item-text">AcademicGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://chatwithpaper.org/" title="Chatpaper"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/芒果.svg" alt="Chatpaper"><span class="back-menu-item-text">Chatpaper</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">其他</div><div class="back-menu-list"><a class="back-menu-item" target="_blank" rel="noopener" href="https://memos.mgodmonkey.cn/" title="Memos"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/圣女果.svg" alt="Memos"><span class="back-menu-item-text">Memos</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://github.com/MGod-monkey/Must_Pass_Experiment_of_TY" title="必过通原"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/苹果.svg" alt="必过通原"><span class="back-menu-item-text">必过通原</span></a></div></div></div></div><a id="site-name" href="/" accesskey="h"><div class="title">MGodmonkeyの世界</div><i class="anzhiyufont anzhiyu-icon-house-chimney"></i></a></span><div class="mask-name-container"><div id="name-container"><a id="page-name" href="javascript:anzhiyu.scrollToDest(0, 500)">PAGE_NAME</a></div></div><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>文章</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-kele"></use></svg> <span>归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-zhaji"></use></svg> <span>标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-denglong"></use></svg> <span>分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>休闲</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://music.mgodmonkey.cn"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-erji"></use></svg> <span>音乐</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/life/bangumis/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-kafei"></use></svg> <span>番剧</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/life/air-conditioner"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-chonglang"></use></svg> <span>空调</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>社交</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/comments/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon--chat"></use></svg> <span>留言板</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-zhaopian_1"></use></svg> <span>相册集</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/MyFavoriteBaby/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xingsu"></use></svg> <span>大陆养虾</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/social/link/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_shu"></use></svg> <span>加入友链</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>个人</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/personal/essay/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_qizhi"></use></svg> <span>说说</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/personal/task_list/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_xiaoya"></use></svg> <span>清单</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/personal/equipment/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_xigua"></use></svg> <span>装备</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/personal/about/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_aixin"></use></svg> <span>关于</span></a></li></ul></div></div></div><div id="nav-right"><div class="nav-button only-home" id="travellings_button" title="随机前往一个开往项目网站"><a class="site-page" onclick="anzhiyu.totraveling()" title="随机前往一个开往项目网站" href="javascript:void(0);" rel="external nofollow" data-pjax-state="external"><i class="anzhiyufont anzhiyu-icon-train"></i></a></div><div class="nav-button" id="randomPost_button"><a class="site-page" onclick="toRandomPost()" title="随机前往一个文章" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-dice"></i></a></div><div class="nav-button" id="search-button"><a class="site-page social-icon search" href="javascript:void(0);" title="搜索🔍" accesskey="s"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i> <span>搜索</span></a></div><input id="center-console" type="checkbox"><label class="widget" for="center-console" title="中控台" onclick="anzhiyu.switchConsole()"><i class="left"></i><i class="widget center"></i><i class="widget right"></i></label><div id="console"><div class="console-card-group-reward"><ul class="reward-all console-card"><li class="reward-item"><a href="https://mybog.s3.bitiful.net/imgs/reward_wechat.png" target="_blank"><img class="post-qr-code-img" alt="微信" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/reward_wechat.png"></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://mybog.s3.bitiful.net/imgs/reward_alipay.png" target="_blank"><img class="post-qr-code-img" alt="支付宝" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/reward_alipay.png"></a><div class="post-qr-code-desc">支付宝</div></li></ul></div><div class="console-card-group"><div class="console-card-group-left"><div class="console-card" id="card-newest-comments"><div class="card-content"><div class="author-content-item-tips">互动</div><span class="author-content-item-title">最新评论</span></div><div class="aside-list"><span>正在加载中...</span></div></div></div><div class="console-card-group-right"><div class="console-card tags"><div class="card-content"><div class="author-content-item-tips">音乐</div><span class="author-content-item-title">灵魂的碰撞💥</span></div></div><div class="console-card history"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-box-archiv"></i><span>文章</span></div><div class="card-archives"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-archive"></i><span>归档</span><a class="card-more-btn" href="/archives/" title="查看更多"><i class="anzhiyufont anzhiyu-icon-angle-right"></i></a></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/06/"><span class="card-archive-list-date">六月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">1</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/05/"><span class="card-archive-list-date">五月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">1</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/04/"><span class="card-archive-list-date">四月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">1</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/03/"><span class="card-archive-list-date">三月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">1</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/02/"><span class="card-archive-list-date">二月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">2</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/09/"><span class="card-archive-list-date">九月 2023</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">1</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/08/"><span class="card-archive-list-date">八月 2023</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">5</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/07/"><span class="card-archive-list-date">七月 2023</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">7</span><span>篇</span></div></a></li></ul></div><hr></div></div></div><div class="button-group"><div class="console-btn-item"><a class="darkmode_switchbutton" title="显示模式切换" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-moon"></i></a></div><div class="console-btn-item" id="consoleHideAside" onclick="anzhiyu.hideAsideBtn()" title="边栏显示控制"><a class="asideSwitch"><i class="anzhiyufont anzhiyu-icon-arrows-left-right"></i></a></div><div class="console-btn-item on" id="consoleCommentBarrage" onclick="anzhiyu.switchCommentBarrage()" title="热评开关"><a class="commentBarrage"><i class="anzhiyufont anzhiyu-icon-message"></i></a></div><div class="console-btn-item" id="consoleMusic" onclick="anzhiyu.musicToggle()" title="音乐开关"><a class="music-switch"><i class="anzhiyufont anzhiyu-icon-music"></i></a></div><div class="console-btn-item" id="consoleKeyboard" onclick="anzhiyu.keyboardToggle()" title="快捷键开关"><a class="keyboard-switch"><i class="anzhiyufont anzhiyu-icon-keyboard"></i></a></div></div><div class="console-mask" onclick="anzhiyu.hideConsole()" href="javascript:void(0);"></div></div><div class="nav-button" id="nav-totop"><a class="totopbtn" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i><span id="percent" onclick="anzhiyu.scrollToDest(0,500)">0</span></a></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);" title="切换"><i class="anzhiyufont anzhiyu-icon-bars"></i></a></div></div></div></nav><div id="post-info"><div id="post-firstinfo"><div class="meta-firstline"><a class="post-meta-original">原创</a><span class="post-meta-categories"><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-inbox post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E7%9F%A5%E8%AF%86%E5%88%86%E4%BA%AB/" itemprop="url">知识分享</a></span><span class="article-meta tags"><a class="article-meta__tags" href="/tags/ros/" tabindex="-1" itemprop="url"><span><i class="anzhiyufont anzhiyu-icon-hashtag"></i> ros</span></a></span></div></div><h1 class="post-title" itemprop="name headline">ROS1&amp;2之CmakeList.txt与package.xml</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="anzhiyufont anzhiyu-icon-calendar-days post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" itemprop="dateCreated datePublished" datetime="2023-07-26T03:37:07.000Z" title="发表于 2023-07-26 11:37:07">2023-07-26</time><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-history post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" itemprop="dateCreated datePublished" datetime="2024-06-18T08:31:53.379Z" title="更新于 2024-06-18 16:31:53">2024-06-18</time></span></div><div class="meta-secondline"><span class="post-meta-separator"></span><span class="post-meta-wordcount"><i class="anzhiyufont anzhiyu-icon-file-word post-meta-icon" title="文章字数"></i><span class="post-meta-label" title="文章字数">字数总计:</span><span class="word-count" title="文章字数">2547</span><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-clock post-meta-icon" title="阅读时长"></i><span class="post-meta-label" title="阅读时长">阅读时长:</span><span>10分钟</span></span><span class="post-meta-separator"></span><span class="post-meta-position" title="作者IP属地为广西"><i class="anzhiyufont anzhiyu-icon-location-dot"></i> 广西</span></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s58 18 88 18 58-18 88-18 58 18 88 18v44h-352Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section><div id="post-top-cover"><img class="nolazyload" id="post-top-bg" src="https://mybog.s3.bitiful.net/imgs/cover/cover_5.webp?_r_=959f8357-85a7-938e-e8c5-1c0e1441933e"></div></header><main id="blog-container"><div class="layout" id="content-inner"><div id="post"><div class="post-ai-description"><div class="ai-title"><i class="anzhiyufont anzhiyu-icon-bilibili"></i><div class="ai-title-text">AI-摘要</div><i class="anzhiyufont anzhiyu-icon-arrow-rotate-right"></i><i class="anzhiyufont anzhiyu-icon-circle-dot" title="朗读摘要"></i><div id="ai-tag">MGodのGPT</div></div><div class="ai-explanation">AI初始化中...</div><div class="ai-btn-box"><div class="ai-btn-item">介绍自己</div><div class="ai-btn-item">生成本文简介</div><div class="ai-btn-item">推荐相关文章</div><div class="ai-btn-item">前往主页</div><div class="ai-btn-item" id="go-tianli-blog">前往爱发电购买</div></div><script data-pjax src="/js/anzhiyu/ai_abstract.js"></script></div><article class="post-content" id="article-container" itemscope itemtype="https://www.mgodmonkey.cn/posts/5d383f12.html"><header><a class="post-meta-categories" href="/categories/%E7%9F%A5%E8%AF%86%E5%88%86%E4%BA%AB/" itemprop="url">知识分享</a><a href="/tags/ros/" tabindex="-1" itemprop="url">ros</a><h1 id="CrawlerTitle" itemprop="name headline">ROS1&amp;2之CmakeList.txt与package.xml</h1><span itemprop="author" itemscope itemtype="http://schema.org/Person">MGodmonkey</span><time itemprop="dateCreated datePublished" datetime="2023-07-26T03:37:07.000Z" title="发表于 2023-07-26 11:37:07">2023-07-26</time><time itemprop="dateCreated datePublished" datetime="2024-06-18T08:31:53.379Z" title="更新于 2024-06-18 16:31:53">2024-06-18</time></header><h2 id="1-CMakeLists-txt与package-xml的作用">1. CMakeLists.txt与package.xml的作用</h2><p>在<strong>ROS</strong>系统的功能包中 要包含 <strong>CMakeLists.txt</strong> 与 <strong>package.xml</strong> 文件来编译功能包的内容</p><p><strong>CMakeLists.txt</strong>原本是<strong>Cmake</strong>编译系统的规则文件，而<strong>Catkin</strong>编译系统基本沿用了<strong>CMake</strong>的编译风格，只是针对<strong>ROS</strong>工程添加了一些宏定义。所以在写法上，<strong>catkin</strong> 的 <strong>CMakeLists.txt</strong>与<strong>CMake</strong>的基本一致。用<strong>cmake</strong>命令创建<strong>功能包</strong>时，会自动生成<strong>CMakeList.txt</strong>文件，已配置了多数编译选项，且包含详细的注释，只需稍作修改便可编译自己的文件。</p><p>而<strong>package.xml</strong>文件是描述功能包清单的文件，包括功能包的<strong>名称</strong>、<strong>版本号</strong>、<strong>作者信息</strong>、<strong>许可信息</strong>、<strong>编译依赖</strong>和<strong>运行依赖</strong>等。</p><p>所以 <strong>CMakeLists.txt</strong> 非常重要，它指定了由源码到目标文件的规则，<strong>catkin</strong>编译系统在工作时首先会找到每个<strong>package</strong>下的 <strong>CMakeLists.txt</strong> ，然后按照规则来编译构建</p><h2 id="2-生成CMakeLists-txt">2. 生成CMakeLists.txt</h2><h3 id="2-1-ROS1">2.1 ROS1</h3><p><strong>ROS1</strong>可通过用<strong>catkin_create_pkg</strong>命令<strong>创建功能包</strong>，这会自动生成<strong>CMakeLists.txt</strong>和<strong>package.xml</strong>文件的。</p><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 创建工作空间</span></span><br><span class="line"><span class="built_in">mkdir</span> -p ~/catkin_ws/src</span><br><span class="line"><span class="built_in">cd</span> ~/catkin_ws/src</span><br><span class="line"></span><br><span class="line"><span class="comment"># 注：std msgs rospy roscpp为创建功能时指定的铱赖，test为包名</span></span><br><span class="line"><span class="comment"># 也可以先不指定，后面在CMakeLists.txt和package.xmL中手动添加</span></span><br><span class="line">catkin_create_pkg <span class="built_in">test</span> std_msgs rospy roscpp</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看一下在~/catkin_ws/src目录下自动生成了哪些文件夹和文件</span></span><br><span class="line">tree</span><br></pre></td></tr></table></figure><blockquote><p>通过上面的命令生成的<strong>工作空间</strong>如下</p><p><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://s2.loli.net/2023/10/03/KUqakLAr3D5ibR6.png" alt=""></p><p><code>include</code>：存放**.h**的头文件</p><p><code>src</code>：可同时存放**.cpp<strong>或</strong>.py<strong>的源文件，但一般</strong>.py**文件存放在<code>scripts</code>目录中</p><p><code>scripts</code>：习惯存放**.py<strong>的</strong>python**文件，需要自己创建</p><p><strong>注：python代码和c++代码不分家，可同时存放在同一功能包中</strong></p></blockquote><h3 id="2-2-ROS2">2.2 ROS2</h3><p><strong>ROS2</strong>可通过如下的命令来<strong>创建功能包</strong>以及必要的<strong>CMakeList.txt</strong>和<strong>package.xml</strong>文件</p><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 创建工作空间</span></span><br><span class="line"><span class="built_in">mkdir</span> -p ~/dev_ws/src</span><br><span class="line"><span class="built_in">cd</span> ~/dev_ws/src</span><br><span class="line"></span><br><span class="line"><span class="comment"># ament_cmake和ament_python分别代表c++和python两种代码的功能包</span></span><br><span class="line"><span class="comment"># test_c和test_python代表包名</span></span><br><span class="line">ros2 pkg create --build-type ament_cmake test_c</span><br><span class="line">ros2 pkg create --build-type ament_python test_python</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看一下在~/dev_ws/src目录下自动生成了哪些文件夹和文件</span></span><br><span class="line">tree</span><br></pre></td></tr></table></figure><blockquote><p>通过以上命令生成的工作空间如下：</p><p><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://s2.loli.net/2023/10/03/NgDJKjklTEWPo3c.png" alt=""></p><ul><li><p><code>test_c/include</code>：存放**.h**的头文件</p></li><li><p><code>test_c/src</code>：存放**.cpp<strong>的</strong>C++**源文件</p></li><li><p><code>test_python/test_python</code>：存放**.py<strong>的</strong>python**文件</p></li></ul><p><strong>注：与ROS1不同，同一功能包内只能同时包含python文件或者C++文件中的一种</strong></p></blockquote><h2 id="3-CMakeLists-txt编写">3. CMakeLists.txt编写</h2><h3 id="3-1-ROS1">3.1 ROS1</h3><ol><li>常用的<strong>ROS1</strong>中<strong>CMakeLists.txt</strong>架构如下</li></ol><blockquote><p>视频解析参考：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1mJ411R7Ni?p=7">中科院软件所-机器人操作系统入门（ROS入门教程）</a></p></blockquote><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">cmake_minimum_required</span>()	<span class="comment">#CMake的最低版本号</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">project</span>()					<span class="comment">#项目名称</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">find_package</span>()				<span class="comment">#找到编译需要的其他CMake/Catkin	package </span></span><br><span class="line"></span><br><span class="line">catkin_python_setup()		<span class="comment">#catkin新加宏，打开catkin的Python Module的支持</span></span><br><span class="line"></span><br><span class="line">add_message_files()			<span class="comment">#catkin新加宏，添加自定义Message文件 </span></span><br><span class="line"></span><br><span class="line">add_service_files()         <span class="comment">#catkin新加宏，添加自定义Service文件 </span></span><br><span class="line"></span><br><span class="line">add_action_files()          <span class="comment">#catkin新加宏，添加自定义Action文件 </span></span><br><span class="line"></span><br><span class="line">generate_message()			<span class="comment">#catkin新加宏，生成不同语言版本的msg/srv/action接口 </span></span><br><span class="line"></span><br><span class="line">catkin_package()			<span class="comment">#catkin新加宏，生成当前package的cmake配置，供依赖本包的其他软件包调用 </span></span><br><span class="line"></span><br><span class="line"><span class="keyword">add_library</span>()				<span class="comment">#生成库 </span></span><br><span class="line"></span><br><span class="line"><span class="keyword">add_executable</span>()			<span class="comment">#生成可执行二进制文件</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">add_dependencies</span>()			<span class="comment">#定义目标文件依赖于其他目标文件，确保其他目标已被构建 </span></span><br><span class="line"></span><br><span class="line"><span class="keyword">target_link_libraries</span>()		<span class="comment">#链接</span></span><br><span class="line"></span><br><span class="line">catkin_add_gtest()			<span class="comment">#catkin新加宏，生成测试</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">install</span>()					<span class="comment">#生成可安装目标</span></span><br></pre></td></tr></table></figure><p>需要自己配置的项目一般就下面几种：</p><ul><li><p><strong>include_directories</strong></p><ul><li>用于设置头文件的相对路径</li><li>全局路径默认为功能包所在目录，功能包的头文件一般放在功能包根目录下的include文件夹，<br>所以需要此处添加此文件夹</li><li>还包含<strong>catkin</strong>编译器默认的其他头文件路径，如：ROS默认安装路径、Linux系统路径等</li></ul></li><li><p><strong>add_exectuable</strong></p><ul><li>用于设置需要编译的代码和可执行文件</li><li>第一个参数为期望生成的可执行文件（节点）名称</li><li>后面的参数为参与编译的源文件(.cpp)，若需要多个代码文件，可依次列出，空格分隔</li></ul></li><li><p><strong>target_link_libraries</strong></p><ul><li>用于设置链接库</li><li>有些功需要使用系统或第三方库函数，通过该选项可以配置执行文件链接的库文件</li><li>第一个参数与<strong>add_exectuable</strong>相同，为可执行文件（节点）名称</li><li>后面的参数为需要链接的库，依次列出，空格分隔</li></ul></li><li><p><strong>add_dependencies</strong></p><ul><li>用于设置依赖</li><li>有时候需要自定义消息类型，消息类型会在编译过程中产生相应语言的代码。若编译的可执行文<br>件依赖这些动态生成的代码，则需要添加${PROJECT NAME}generate messages_cpp配置</li></ul></li><li><p>自定义数据类型：消息<strong>msg</strong>、服务<strong>srv</strong>、动作<strong>action</strong></p><ul><li><strong>find_package</strong>(catkin REQUIRE COMPONENTS message_generation)</li><li><strong>catkin_package</strong>(CATKIN_DEPENDS message_runtime)</li><li><strong>add_message_files</strong>(FILES xxx.msg)</li><li><strong>add_service_files</strong>(FILES xxx.srv)</li><li><strong>add_action_files</strong>(FILES xxx.action)</li><li><strong>generate_messages</strong>(DEPENDENCIES std_msgs)</li></ul></li></ul><blockquote><p>CMakeLists.txt模板参考：<a target="_blank" rel="noopener" href="https://mybog.s3.bitiful.net/ros/zero/CMakeLists.txt">CMakeLists.txt</a></p><p>更多教程参考：<a target="_blank" rel="noopener" href="http://wiki.ros.org/catkin/CMakeLists.txt">catkin/CMakeLists.txt - ROS Wiki</a></p></blockquote><h3 id="3-2-ROS2">3.2 ROS2</h3><p>常用的<strong>ROS2</strong>中<strong>CMakeLists.txt</strong>架构如下</p><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">cmake_minimum_required</span>()			<span class="comment">#CMake的最低版本号</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">project</span>()				  		   <span class="comment">#项目名称</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">find_package</span>()   				    <span class="comment">#查找系统中的依赖项</span></span><br><span class="line"></span><br><span class="line">ament_target_dependencies()          <span class="comment">#依赖于其他目标文件，确保其他目标已被构建 </span></span><br><span class="line"></span><br><span class="line"><span class="keyword">add_executable</span>()				    <span class="comment">#生成可执行二进制文件</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">install</span>()						   <span class="comment">#生成可安装目标</span></span><br><span class="line"></span><br><span class="line">ament_package()						<span class="comment">#生成功能包</span></span><br><span class="line"></span><br><span class="line">rosidl_generate_interfaces()		<span class="comment"># 自定义消息类型接口</span></span><br></pre></td></tr></table></figure><p>示例模板如下</p><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">cmake_minimum_required</span>(VERSION <span class="number">3.5</span>)</span><br><span class="line"><span class="keyword">project</span>(test_c)</span><br><span class="line"></span><br><span class="line"><span class="comment"># Default to C99</span></span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">NOT</span> CMAKE_C_STANDARD)</span><br><span class="line">  <span class="keyword">set</span>(CMAKE_C_STANDARD <span class="number">99</span>)</span><br><span class="line"><span class="keyword">endif</span>()</span><br><span class="line"></span><br><span class="line"><span class="comment"># Default to C++14</span></span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">NOT</span> CMAKE_CXX_STANDARD)</span><br><span class="line">  <span class="keyword">set</span>(CMAKE_CXX_STANDARD <span class="number">14</span>)</span><br><span class="line"><span class="keyword">endif</span>()</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(CMAKE_COMPILER_IS_GNUCXX <span class="keyword">OR</span> CMAKE_CXX_COMPILER_ID <span class="keyword">MATCHES</span> <span class="string">&quot;Clang&quot;</span>)</span><br><span class="line">  <span class="keyword">add_compile_options</span>(-Wall -Wextra -Wpedantic)</span><br><span class="line"><span class="keyword">endif</span>()</span><br><span class="line"></span><br><span class="line"><span class="comment"># find dependencies</span></span><br><span class="line"><span class="keyword">find_package</span>(ament_cmake REQUIRED)</span><br><span class="line"><span class="keyword">find_package</span>(rclcpp REQUIRED)</span><br><span class="line"><span class="keyword">find_package</span>(std_msgs REQUIRED)</span><br><span class="line"><span class="comment"># uncomment the following section in order to fill in</span></span><br><span class="line"><span class="comment"># further dependencies manually.</span></span><br><span class="line"><span class="comment"># find_package(&lt;dependency&gt; REQUIRED)</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">add_executable</span>(talker src/publisher_member_function.cpp)	<span class="comment"># 修改2</span></span><br><span class="line">ament_target_dependencies(talker rclcpp std_msgs)			<span class="comment"># 修改3</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">install</span>(TARGETS</span><br><span class="line">  talker												<span class="comment"># 修改4</span></span><br><span class="line">  DESTINATION lib/<span class="variable">$&#123;PROJECT_NAME&#125;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(BUILD_TESTING)</span><br><span class="line">  <span class="keyword">find_package</span>(ament_lint_auto REQUIRED)</span><br><span class="line">  <span class="comment"># the following line skips the linter which checks for copyrights</span></span><br><span class="line">  <span class="comment"># uncomment the line when a copyright and license is not present in all source files</span></span><br><span class="line">  <span class="comment">#set(ament_cmake_copyright_FOUND TRUE)</span></span><br><span class="line">  <span class="comment"># the following line skips cpplint (only works in a git repo)</span></span><br><span class="line">  <span class="comment"># uncomment the line when this package is not in a git repo</span></span><br><span class="line">  <span class="comment">#set(ament_cmake_cpplint_FOUND TRUE)</span></span><br><span class="line">  ament_lint_auto_find_test_dependencies()</span><br><span class="line"><span class="keyword">endif</span>()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 添加自定义消息类型需要添加项</span></span><br><span class="line"><span class="keyword">find_package</span>(geometry_msgs REQUIRED)</span><br><span class="line"><span class="keyword">find_package</span>(rosidl_default_generators REQUIRED)</span><br><span class="line"></span><br><span class="line">rosidl_generate_interfaces(<span class="variable">$&#123;PROJECT_NAME&#125;</span></span><br><span class="line">  <span class="string">&quot;msg/Num.msg&quot;</span>				<span class="comment"># 自定义1</span></span><br><span class="line">  <span class="string">&quot;msg/Sphere.msg&quot;</span>			<span class="comment"># 自定义2</span></span><br><span class="line">  <span class="string">&quot;srv/AddThreeInts.srv&quot;</span>     <span class="comment"># 自定义3</span></span><br><span class="line">  DEPENDENCIES geometry_msgs</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">ament_package()</span><br></pre></td></tr></table></figure><blockquote><p>相较于基于<strong>catkin</strong>的<strong>CMake</strong>文件，基于<strong>ament</strong>的明显简洁很多</p></blockquote><p>假设你编写了<code>~/dev_ws/src/test.cpp</code>文件后，需要修改的步骤如下：</p><ol><li>链接源代码</li></ol><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">add_executable</span>(<span class="keyword">test</span> src/<span class="keyword">test</span>.cpp)	<span class="comment"># test为你输入节点后执行的名称，如ros2 run test_c test（前一个test_c为包名，后一个test则为这里的设置的名称，代表具体执行的代码）</span></span><br><span class="line">ament_target_dependencies(<span class="keyword">test</span> rclcpp)	<span class="comment"># 添加依赖项</span></span><br></pre></td></tr></table></figure><ol start="2"><li>添加下面这两行代码的目的是让编译器编译<code>~/dev_ws/src/test_c/test.cpp</code>这个文件</li></ol><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">install</span>(TARGETS</span><br><span class="line">  <span class="keyword">test</span></span><br><span class="line">  DESTINATION lib/<span class="variable">$&#123;PROJECT_NAME&#125;</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure><p>当你自定义消息类型时还需要消息类型文件</p><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 添加自定义消息类型需要添加项</span></span><br><span class="line"><span class="comment"># 下面两项是固定的，geometry_msgs是用于生成消息依赖包</span></span><br><span class="line"><span class="keyword">find_package</span>(geometry_msgs REQUIRED)</span><br><span class="line"><span class="keyword">find_package</span>(rosidl_default_generators REQUIRED)</span><br><span class="line"></span><br><span class="line">rosidl_generate_interfaces(<span class="variable">$&#123;PROJECT_NAME&#125;</span></span><br><span class="line">  <span class="string">&quot;msg/Num.msg&quot;</span>				<span class="comment"># 自定义1</span></span><br><span class="line">  <span class="string">&quot;msg/Sphere.msg&quot;</span>			<span class="comment"># 自定义2</span></span><br><span class="line">  <span class="string">&quot;srv/AddThreeInts.srv&quot;</span>     <span class="comment"># 自定义3</span></span><br><span class="line">  DEPENDENCIES geometry_msgs</span><br><span class="line">)</span><br></pre></td></tr></table></figure><h2 id="4-package-xml编写">4. package.xml编写</h2><p><strong>package.xml</strong>的框架如下</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">package</span> <span class="attr">format</span>=<span class="string">&quot;3&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">name</span>&gt;</span>..<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>0.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">description</span>&gt;</span>...<span class="tag">&lt;/<span class="name">description</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">maintainer</span> <span class="attr">email</span>=<span class="string">&quot;lanhanba@todo.todo&quot;</span>&gt;</span>...<span class="tag">&lt;/<span class="name">maintainer</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">license</span>&gt;</span>...<span class="tag">&lt;/<span class="name">license</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">buildtool_depend</span>&gt;</span>...<span class="tag">&lt;/<span class="name">buildtool_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">exec_depend</span>&gt;</span>...<span class="tag">&lt;/<span class="name">exec_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">exec_depend</span>&gt;</span>...<span class="tag">&lt;/<span class="name">exec_depend</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">export</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">build_type</span>&gt;</span>...<span class="tag">&lt;/<span class="name">build_type</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">export</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">package</span>&gt;</span></span><br></pre></td></tr></table></figure><blockquote><p>相较于<strong>CMakeList.txt</strong>，<strong>package.xml</strong>的语法就简单许多，且<strong>ROS1</strong>和<strong>ROS2</strong>的标签语法通用</p><ul><li><strong>&lt;build_depend&gt;&lt;/build_depend&gt;</strong>: 标签定义了功能包中代码编译时所依赖的其他功能包</li><li><strong>&lt;exec_depend&gt;&lt;exec_depend&gt;</strong>: 标签定义了功能包中可执行程序运行时所依赖的其他功能包</li><li><strong>自定义数据类型</strong>：话题消息<strong>msg</strong>、服务数据<strong>srv</strong>、动作数据<strong>action</strong></li></ul></blockquote><p>模板如下</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;?xml-model href=<span class="string">&quot;http://download.ros.org/schema/package_format3.xsd&quot;</span> schematypens=<span class="string">&quot;http://www.w3.org/2001/XMLSchema&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">package</span> <span class="attr">format</span>=<span class="string">&quot;3&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">name</span>&gt;</span>test_c<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>0.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">description</span>&gt;</span>TODO: Package description<span class="tag">&lt;/<span class="name">description</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">maintainer</span> <span class="attr">email</span>=<span class="string">&quot;lanhanba@todo.todo&quot;</span>&gt;</span>lanhanba<span class="tag">&lt;/<span class="name">maintainer</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">license</span>&gt;</span>TODO: License declaration<span class="tag">&lt;/<span class="name">license</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">&lt;!-- ROS1 --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">buildtool_depend</span>&gt;</span>catkin<span class="tag">&lt;/<span class="name">buildtool_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">build_depend</span>&gt;</span>roscpp<span class="tag">&lt;/<span class="name">build_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">build_depend</span>&gt;</span>rospy<span class="tag">&lt;/<span class="name">build_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">build_depend</span>&gt;</span>std_msgs<span class="tag">&lt;/<span class="name">build_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">build_export_depend</span>&gt;</span>roscpp<span class="tag">&lt;/<span class="name">build_export_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">build_export_depend</span>&gt;</span>rospy<span class="tag">&lt;/<span class="name">build_export_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">build_export_depend</span>&gt;</span>std_msgs<span class="tag">&lt;/<span class="name">build_export_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">exec_depend</span>&gt;</span>roscpp<span class="tag">&lt;/<span class="name">exec_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">exec_depend</span>&gt;</span>rospy<span class="tag">&lt;/<span class="name">exec_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">exec_depend</span>&gt;</span>std_msgs<span class="tag">&lt;/<span class="name">exec_depend</span>&gt;</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">&lt;!-- ROS2_C++ --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">buildtool_depend</span>&gt;</span>ament_cmake<span class="tag">&lt;/<span class="name">buildtool_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">test_depend</span>&gt;</span>ament_lint_auto<span class="tag">&lt;/<span class="name">test_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">test_depend</span>&gt;</span>ament_lint_common<span class="tag">&lt;/<span class="name">test_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">export</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">build_type</span>&gt;</span>ament_cmake<span class="tag">&lt;/<span class="name">build_type</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">export</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">  <span class="comment">&lt;!-- ROS2_python --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">test_depend</span>&gt;</span>ament_copyright<span class="tag">&lt;/<span class="name">test_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">test_depend</span>&gt;</span>ament_flake8<span class="tag">&lt;/<span class="name">test_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">test_depend</span>&gt;</span>ament_pep257<span class="tag">&lt;/<span class="name">test_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">test_depend</span>&gt;</span>python3-pytest<span class="tag">&lt;/<span class="name">test_depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">export</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">build_type</span>&gt;</span>ament_python<span class="tag">&lt;/<span class="name">build_type</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">export</span>&gt;</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">&lt;!-- ROS2中C++功能包添加自定义消息类型还需添加下面三行（固定形式，和上面的CMake修改搭配使用，python不需要） --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">depend</span>&gt;</span>rosidl_default_generators<span class="tag">&lt;/<span class="name">depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">depend</span>&gt;</span>geometry_msgs<span class="tag">&lt;/<span class="name">depend</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">member_of_group</span>&gt;</span>rosidl_interface_packages<span class="tag">&lt;/<span class="name">member_of_group</span>&gt;</span></span><br><span class="line">    </span><br><span class="line"><span class="tag">&lt;/<span class="name">package</span>&gt;</span></span><br></pre></td></tr></table></figure><h2 id="5-其他–Setup-py的修改">5. 其他–Setup.py的修改</h2><p>在<strong>ROS2-Python</strong>功能包中，如果添加类似<code>~/dev_ws/src/test_python/test.py</code>的<strong>python</strong>文件，则需要对功能包中的<strong><a target="_blank" rel="noopener" href="http://Setup.py">Setup.py</a></strong>进行如下的修改</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> setuptools <span class="keyword">import</span> setup</span><br><span class="line"></span><br><span class="line">package_name = <span class="string">&#x27;test_python&#x27;</span></span><br><span class="line"></span><br><span class="line">setup(</span><br><span class="line">    name=package_name,</span><br><span class="line">    version=<span class="string">&#x27;0.0.0&#x27;</span>,</span><br><span class="line">    packages=[package_name],</span><br><span class="line">    data_files=[</span><br><span class="line">        (<span class="string">&#x27;share/ament_index/resource_index/packages&#x27;</span>,</span><br><span class="line">            [<span class="string">&#x27;resource/&#x27;</span> + package_name]),</span><br><span class="line">        (<span class="string">&#x27;share/&#x27;</span> + package_name, [<span class="string">&#x27;package.xml&#x27;</span>]),</span><br><span class="line">    ],</span><br><span class="line">    install_requires=[<span class="string">&#x27;setuptools&#x27;</span>],</span><br><span class="line">    zip_safe=<span class="literal">True</span>,</span><br><span class="line">    maintainer=<span class="string">&#x27;lanhanba&#x27;</span>,</span><br><span class="line">    maintainer_email=<span class="string">&#x27;lanhanba@todo.todo&#x27;</span>,</span><br><span class="line">    description=<span class="string">&#x27;TODO: Package description&#x27;</span>,</span><br><span class="line">    license=<span class="string">&#x27;TODO: License declaration&#x27;</span>,</span><br><span class="line">    tests_require=[<span class="string">&#x27;pytest&#x27;</span>],</span><br><span class="line">    entry_points=&#123;</span><br><span class="line">        <span class="string">&#x27;console_scripts&#x27;</span>: [</span><br><span class="line">            <span class="comment"># 结构如下：节点名 = 功能包名.代码文件.执行入口函数名(一般执行入口函数名都是main，也就是说python代码中一般要有main函数)</span></span><br><span class="line">            <span class="comment"># 通过ros2 run test_python test 来执行test_python.test:main下的函数</span></span><br><span class="line">            <span class="comment"># 如果有多个python代码文件都需要一一添加，名称不能一样</span></span><br><span class="line">            <span class="string">&quot;test = test_python.test:main&quot;</span>,</span><br><span class="line">            <span class="string">&quot;test2 = test_python.test2:main&quot;</span></span><br><span class="line">        ],</span><br><span class="line">    &#125;,</span><br><span class="line">)</span><br></pre></td></tr></table></figure><blockquote><p><strong>参考：</strong></p><ul><li><p><a target="_blank" rel="noopener" href="http://wiki.ros.org/catkin/CMakeLists.txt">catkin/CMakeLists.txt - ROS Wiki</a></p></li><li><p><a target="_blank" rel="noopener" href="https://docs.ros.org/en/humble/Tutorials">CMakeLists.txt - ROS Humble Wiki</a></p></li><li><p><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/94579820">【ROS 学习笔记】CMakeLists.txt 与 package.xml - 知乎 (zhihu.com)</a></p></li><li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/shoufei403/article/details/125831552">详细分析一个ROS2 CMakeLists.txt文件_首飞爱玩机器人的博客-CSDN博客</a></p></li></ul></blockquote></article><div class="post-copyright"><div class="copyright-cc-box"><i class="anzhiyufont anzhiyu-icon-copyright"></i></div><div class="post-copyright__author_box"><a class="post-copyright__author_img" href="/" title="头像"><img class="post-copyright__author_img_back" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/head.jpg" title="头像" alt="头像"><img class="post-copyright__author_img_front" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/head.jpg" title="头像" alt="头像"></a><div class="post-copyright__author_name">MGodmonkey</div><div class="post-copyright__author_desc">不在沉默中沉沦</div></div><div class="post-copyright__post__info"><a class="post-copyright__original" title="该文章为原创文章，注意版权协议" href="https://www.mgodmonkey.cn/posts/5d383f12.html">原创</a><a class="post-copyright-title"><span onclick='rm.copyPageUrl("https://www.mgodmonkey.cn/posts/5d383f12.html")'>ROS1&amp;2之CmakeList.txt与package.xml</span></a></div><div class="post-tools" id="post-tools"><div class="post-tools-left"><div class="rewardLeftButton"><div class="post-reward" onclick="anzhiyu.addRewardMask()"><div class="reward-button button--animated" title="赞赏作者"><i class="anzhiyufont anzhiyu-icon-hand-heart-fill"></i>打赏作者</div><div class="reward-main"><div class="reward-all"><span class="reward-title">感谢你赐予我前进的力量</span><ul class="reward-group"><li class="reward-item"><a href="https://mybog.s3.bitiful.net/imgs/reward_wechat.png" target="_blank"><img class="post-qr-code-img" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/reward_wechat.png" alt="微信"></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://mybog.s3.bitiful.net/imgs/reward_alipay.png" target="_blank"><img class="post-qr-code-img" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/reward_alipay.png" alt="支付宝"></a><div class="post-qr-code-desc">支付宝</div></li></ul><a class="reward-main-btn" href="/about/#about-reward" target="_blank"><div class="reward-text">赞赏者名单</div><div class="reward-dec">因为你们的支持让我意识到写文章的价值🙏</div></a></div></div></div><div id="quit-box" onclick="anzhiyu.removeRewardMask()" style="display:none"></div></div><div class="shareRight"><div class="share-link mobile"><div class="share-qrcode"><div class="share-button" title="使用手机访问这篇文章"><i class="anzhiyufont anzhiyu-icon-qrcode"></i></div><div class="share-main"><div class="share-main-all"><div id="qrcode" title="https://www.mgodmonkey.cn/posts/5d383f12.html"></div><div class="reward-dec">使用手机访问这篇文章</div></div></div></div></div><div class="share-link weibo"><a class="share-button" target="_blank" href="https://service.weibo.com/share/share.php?title=ROS1&amp;2之CmakeList.txt与package.xml&amp;url=https://www.mgodmonkey.cn/posts/5d383f12.html&amp;pic=https://mybog.s3.bitiful.net/imgs/cover/cover_5.webp?_r_=959f8357-85a7-938e-e8c5-1c0e1441933e" rel="external nofollow noreferrer noopener"><i class="anzhiyufont anzhiyu-icon-weibo"></i></a></div><script>function copyCurrentPageUrl(){var e=window.location.href,t=document.createElement("input");t.setAttribute("value",e),document.body.appendChild(t),t.select(),t.setSelectionRange(0,99999),document.execCommand("copy"),document.body.removeChild(t)}</script><div class="share-link copyurl"><div class="share-button" id="post-share-url" title="复制链接" onclick="copyCurrentPageUrl()"><i class="anzhiyufont anzhiyu-icon-link"></i></div></div></div></div></div><div class="post-copyright__notice"><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.mgodmonkey.cn" target="_blank">MGodmonkeyの世界</a>！</span></div></div><div class="post-tools-right"><div class="tag_share"><div class="post-meta__box"><div class="post-meta__box__tag-list"><a class="post-meta__box__tags" href="/tags/ros/"><span class="tags-punctuation"><i class="anzhiyufont anzhiyu-icon-tag"></i></span> ros<span class="tagsPageCount">21</span></a></div></div></div><div class="post_share"><div class="social-share" data-image="https://mybog.s3.bitiful.net/imgs/cover/cover_23.webp?_r_=aec10139-1087-2595-464e-c9d9570c297b" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://lib.baomitu.com/social-share.js/1.0.16/css/share.min.css" media="print" onload='this.media="all"'><script src="https://lib.baomitu.com/social-share.js/1.0.16/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/891e492b.html"><img class="prev-cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_4.webp?_r_=634029b1-7337-04ff-bf5b-9bc8392760bb" onerror='onerror=null,src="/img/404.jpg"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">ROS-Launch的使用方式</div></div></a></div><div class="next-post pull-right"><a href="/posts/37a8d87e.html"><img class="next-cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_12.webp?_r_=a6d65e08-9316-6f13-aaa5-9a8ac623bfba" onerror='onerror=null,src="/img/404.jpg"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">ROS-PyQt小案例</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="anzhiyufont anzhiyu-icon-thumbs-up fa-fw" style="font-size:1.5rem;margin-right:4px"></i><span>喜欢这篇文章的人也看了</span></div><div class="relatedPosts-list"><div><a href="/posts/f1cb77fb.html" title="ROS指令大全"><img class="cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_11.webp?_r_=c22c6364-0c20-490e-844b-7addff113b3b" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2023-06-30</div><div class="title">ROS指令大全</div></div></a></div><div><a href="/posts/232d6cf1.html" title="ROS资源汇总"><img class="cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://bu.dusays.com/2023/10/02/651ad2e1606f4.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2023-06-23</div><div class="title">ROS资源汇总</div></div></a></div><div><a href="/posts/982cb875.html" title="从0制作自主空中机器人-5-Airsim-PX4仿真环境搭建"><img class="cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_23.webp?_r_=aec10139-1087-2595-464e-c9d9570c297b" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-06-11</div><div class="title">从0制作自主空中机器人-5-Airsim-PX4仿真环境搭建</div></div></a></div><div><a href="/posts/2c607ad2.html" title="CERLAB无人机自主框架：动态目标检测与跟踪"><img class="cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_7.webp?_r_=0fb1eff9-7ecc-ebd0-88a5-3cac919450f8" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-04-09</div><div class="title">CERLAB无人机自主框架：动态目标检测与跟踪</div></div></a></div><div><a href="/posts/349e2e18.html" title="CERLAB无人机自主框架：环境搭建"><img class="cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/JaEtOo8VKfpsh5M.webp?_r_=d4a584db-f39f-5863-c23e-51d9f43544f5" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-03-26</div><div class="title">CERLAB无人机自主框架：环境搭建</div></div></a></div><div><a href="/posts/4528cc75.html" title="DVXplorer事件相机入门"><img class="cover" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_4.webp?_r_=5cba0e99-1a05-9451-a070-c167c3fcc115" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-02-14</div><div class="title">DVXplorer事件相机入门</div></div></a></div></div></div><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="anzhiyufont anzhiyu-icon-comments"></i> <span>评论</span></div><div class="comment-randomInfo"><a onclick="anzhiyu.addRandomCommentInfo()" href="javascript:void(0)">匿名评论</a><a href="/privacy" style="margin-left:4px">隐私政策</a></div><div class="comment-tips" id="comment-tips"><span>✅ 你无需删除空行，直接评论以获取最佳展示效果</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div><div class="comment-barrage"></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-content"><div class="author-info__sayhi" id="author-info__sayhi" onclick="anzhiyu.changeSayHelloText()"></div><div class="author-info-avatar"><img class="avatar-img" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/head.jpg" onerror='this.onerror=null,this.src="/img/404.webp"' alt="avatar"><div class="author-status"><img class="g-status" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://bu.dusays.com/2023/08/24/64e6ce9c507bb.png" alt="status"></div></div><div class="author-info__description"><div style="line-height:1.38;margin:.1rem 0;text-align:justify;color:rgba(255,255,255,.8)">这里是我的<b style="color:#fff">科研日记本</b>和<b style="color:#fff">学习记录本</b>，目前处于研1阶段，主攻领域为<b style="color:#fff">空中机器人</b>，因此你将会在这看到大量关于<b style="color:#fff">ROS</b>、<b style="color:#fff">无人机</b>、<b style="color:#fff">算法</b>等教程</div><div style="line-height:1.38;margin:.3rem 0;text-align:justify;color:rgba(255,255,255,.8)">希望你能在这里学习到有用的<b style="color:#fff">知识</b>，可以的话可以<b style="color:#fff">收藏本网站😘</b>。</div></div><div class="author-info__bottom-group"><a class="author-info__bottom-group-left" href="/"><h1 class="author-info__name">MGodmonkey</h1><div class="author-info__desc">不在沉默中沉沦</div></a><div class="card-info-social-icons is-center"><a class="social-icon faa-parent animated-hover" href="https://github.com/MGod-monkey" target="_blank" title="Github"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-github"></use></svg></a><a class="social-icon faa-parent animated-hover" href="https://gitee.com/mgod_wu" target="_blank" title="Gitee"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-gitee"></use></svg></a><a class="social-icon faa-parent animated-hover" href="https://blog.csdn.net/qq_45516773" target="_blank" title="CSDN"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-csdn"></use></svg></a></div></div></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-bullhorn anzhiyu-shake"></i><span>公告</span></div><div class="announcement_content"><center>主域名：<br><del><a target="_blank" rel="noopener" href="https://www.mgodmonkey.love"><b><font color="#5ea6e5">mgodmonkey.love(太贵续费不起)</font></b></a></del><br><a href="https://www.mgodmonkey.cn"><b><font color="#5ee5e0">mgodmonkey.cn</font></b></a><br>备用域名：<br><a target="_blank" rel="noopener" href="https://mgod-monkey.github.io/"><b><font color="#5ea6e5">mgodmonkey.github.io</font></b></a><br><a target="_blank" rel="noopener" href="https://mgodmonkey.zeabur.app/"><b><font color="#5ea6e5">mgodmonkey.zeabur.app</font></b></a><br><a href="mailto:mgod_monkey@qq.com">📬：<font color="#a591e0">mgod_monkey@qq.com</font></a></center></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-bars"></i><span>文章目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-CMakeLists-txt%E4%B8%8Epackage-xml%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="toc-text">1. CMakeLists.txt与package.xml的作用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E7%94%9F%E6%88%90CMakeLists-txt"><span class="toc-text">2. 生成CMakeLists.txt</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-ROS1"><span class="toc-text">2.1 ROS1</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-ROS2"><span class="toc-text">2.2 ROS2</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-CMakeLists-txt%E7%BC%96%E5%86%99"><span class="toc-text">3. CMakeLists.txt编写</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-ROS1"><span class="toc-text">3.1 ROS1</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-ROS2"><span class="toc-text">3.2 ROS2</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-package-xml%E7%BC%96%E5%86%99"><span class="toc-text">4. package.xml编写</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E5%85%B6%E4%BB%96%E2%80%93Setup-py%E7%9A%84%E4%BF%AE%E6%94%B9"><span class="toc-text">5. 其他–Setup.py的修改</span></a></li></ol></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div id="footer_deal"><a class="deal_link" href="mailto:mgod_monkey@qq.com" title="email"><i class="anzhiyufont anzhiyufont anzhiyu-icon-envelope"></i></a><a class="deal_link" target="_blank" rel="noopener" href="https://www.facebook.com/profile.php?id=100093287072649&amp;sk=about" title="facebook"><i class="anzhiyufont anzhiyufont anzhiyu-icon-facebook1"></i></a><img class="footer_mini_logo" title="返回顶部" alt="返回顶部" onclick="anzhiyu.scrollToDest(0,500)" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/xx.webp" size="50px"><a class="deal_link" target="_blank" rel="noopener" href="https://github.com/MGod-monkey" title="Github"><i class="anzhiyufont anzhiyufont anzhiyu-icon-github"></i></a><a class="deal_link" target="_blank" rel="noopener" href="https://v.douyin.com/UaF6wSA/" title="抖音"><i class="anzhiyufont anzhiyufont anzhiyu-icon-tiktok"></i></a></div><div id="anzhiyu-footer"><div class="footer-group"><div class="footer-title">服务</div><div class="footer-links"><a class="footer-item" title="51la统计" target="_blank" rel="noopener" href="https://v6.51.la/">51la统计</a><a class="footer-item" title="十年之约" target="_blank" rel="noopener" href="https://www.foreverblog.cn/">十年之约</a><a class="footer-item" title="开往" target="_blank" rel="noopener" href="https://github.com/travellings-link/travellings">开往</a></div></div><div class="footer-group"><div class="footer-title">导航</div><div class="footer-links"><a class="footer-item" title="即刻短文" href="/personal/essay/">即刻短文</a><a class="footer-item" title="友链文章" href="/fcircle/">友链文章</a><a class="footer-item" title="留言板" href="/comments/">留言板</a></div></div><div class="footer-group"><div class="footer-title">协议</div><div class="footer-links"><a class="footer-item" title="隐私协议" href="/privacy/">隐私协议</a><a class="footer-item" title="Cookies" href="/cookies/">Cookies</a><a class="footer-item" title="版权协议" href="/copyright/">版权协议</a></div></div><div class="footer-group"><div class="footer-title-group"><div class="footer-title">友链</div><a class="random-friends-btn" id="footer-random-friends-btn" href="javascript:addFriendLinksInFooter();" title="换一批友情链接"><i class="anzhiyufont anzhiyu-icon-arrow-rotate-right"></i></a></div><div class="footer-links" id="friend-links-in-footer"></div></div></div><div id="workboard"><div id="runtimeTextTip"></div></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" data-title="博客框架Hexo_v6.4.3" title="博客框架Hexo_v6.4.3"><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://sourcebucket.s3.bitiful.net/badge/Frame-Hexo-blue.svg" alt="博客框架Hexo_v6.4.3"></a><a class="github-badge" target="_blank" href="https://docs.anheyu.com/" style="margin-inline:5px" data-title="主题版本Anzhiyu_v1.5.0" title="主题版本Anzhiyu_v1.5.0"><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://npm.elemecdn.com/anzhiyu-theme-static@1.0.9/img/Theme-AnZhiYu-2E67D3.svg" alt="主题版本Anzhiyu_v1.5.0"></a><a class="github-badge" target="_blank" href="https://vercel.com/" style="margin-inline:5px" data-title="本站采用多线部署，主线路托管于Vercel" title="本站采用多线部署，主线路托管于Vercel"><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://sourcebucket.s3.bitiful.net/badge/Hosted-Vercel-brightgreen.svg" alt="本站采用多线部署，主线路托管于Vercel"></a><a class="github-badge" target="_blank" href="https://github.com/" style="margin-inline:5px" data-title="本站项目由Github托管" title="本站项目由Github托管"><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://npm.elemecdn.com/anzhiyu-blog@2.1.5/img/badge/Source-Github.svg" alt="本站项目由Github托管"></a><a class="github-badge" target="_blank" href="https://beian.miit.gov.cn/" style="margin-inline:5px" data-title="本站已完成备案，桂ICP备-2023001814号" title="本站已完成备案，桂ICP备-2023001814号"><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/桂ICP备-2023001814号-1.svg" alt="本站已完成备案，桂ICP备-2023001814号"></a><a class="github-badge" target="_blank" href="https://icp.gov.moe/?keyword=20248520" style="margin-inline:5px" data-title="本站已加入萌ICP豪华套餐，萌ICP备20248520号" title="本站已加入萌ICP豪华套餐，萌ICP备20248520号"><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/mengICP_20248520.svg" alt="本站已加入萌ICP豪华套餐，萌ICP备20248520号"></a><a class="github-badge" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px" data-title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"><img src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://npm.elemecdn.com/anzhiyu-blog@2.2.0/img/badge/Copyright-BY-NC-SA.svg" alt="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a></p></div><div id="footer-bar"><div class="footer-bar-links"><div class="footer-bar-left"><div id="footer-bar-tips"><div class="copyright">&copy;2023 - 2024 By <a class="footer-bar-link" href="/" title="MGodmonkey" target="_blank">MGodmonkey</a></div></div><div id="footer-type-tips"></div><div class="js-pjax"><script>function subtitleType(){fetch("https://v1.hitokoto.cn").then((t=>t.json())).then((t=>{{const e="出自 "+t.from,p=[];p.unshift(t.hitokoto,e),window.typed=new Typed("#footer-type-tips",{strings:p,startDelay:300,typeSpeed:150,loop:!0,backSpeed:50})}}))}"function"==typeof Typed?subtitleType():getScript("https://cdn.cbd.int/typed.js@2.1.0/dist/typed.umd.js").then(subtitleType)</script></div></div><div class="footer-bar-right"><a class="footer-bar-link" target="_blank" rel="noopener" href="https://beian.miit.gov.cn/" title="桂ICP备-2023001814号">桂ICP备-2023001814号</a><a class="footer-bar-link cc" href="/copyright" title="cc协议"><i class="anzhiyufont anzhiyu-icon-copyright-line"></i><i class="anzhiyufont anzhiyu-icon-creative-commons-by-line"></i><i class="anzhiyufont anzhiyu-icon-creative-commons-nc-line"></i><i class="anzhiyufont anzhiyu-icon-creative-commons-nd-line"></i></a></div></div></div></footer></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="sidebar-site-data site-data is-center"><a href="/archives/" title="archive"><div class="headline">文章</div><div class="length-num">32</div></a><a href="/tags/" title="tag"><div class="headline">标签</div><div class="length-num">18</div></a><a href="/categories/" title="category"><div class="headline">分类</div><div class="length-num">13</div></a></div><span class="sidebar-menu-item-title">功能</span><div class="sidebar-menu-item"><a class="darkmode_switchbutton menu-child" href="javascript:void(0);" title="显示模式"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i><span>显示模式</span></a></div><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">网页</div><div class="back-menu-list"><a class="back-menu-item" href="https://www.mgodmonkey.cn/" title="博客"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/favicon.ico" alt="博客"><span class="back-menu-item-text">博客</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">AI项目</div><div class="back-menu-list"><a class="back-menu-item" target="_blank" rel="noopener" href="https://chat.mgodmonkey.cn/" title="ChatGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/圣女果.svg" alt="ChatGPT"><span class="back-menu-item-text">ChatGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://newchat.mgodmonkey.cn/" title="NewChatGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/苹果.svg" alt="NewChatGPT"><span class="back-menu-item-text">NewChatGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://autogpt.mgodmonkey.cn/" title="AutoGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/火龙果.svg" alt="AutoGPT"><span class="back-menu-item-text">AutoGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://academic.chatwithpaper.org/" title="AcademicGPT"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/石榴.svg" alt="AcademicGPT"><span class="back-menu-item-text">AcademicGPT</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://chatwithpaper.org/" title="Chatpaper"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/芒果.svg" alt="Chatpaper"><span class="back-menu-item-text">Chatpaper</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">其他</div><div class="back-menu-list"><a class="back-menu-item" target="_blank" rel="noopener" href="https://memos.mgodmonkey.cn/" title="Memos"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/圣女果.svg" alt="Memos"><span class="back-menu-item-text">Memos</span></a><a class="back-menu-item" target="_blank" rel="noopener" href="https://github.com/MGod-monkey/Must_Pass_Experiment_of_TY" title="必过通原"><img class="back-menu-item-icon" src="" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/苹果.svg" alt="必过通原"><span class="back-menu-item-text">必过通原</span></a></div></div></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>文章</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-kele"></use></svg> <span>归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-zhaji"></use></svg> <span>标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-denglong"></use></svg> <span>分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>休闲</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://music.mgodmonkey.cn"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-erji"></use></svg> <span>音乐</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/life/bangumis/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu-kafei"></use></svg> <span>番剧</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/life/air-conditioner"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-chonglang"></use></svg> <span>空调</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>社交</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/comments/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon--chat"></use></svg> <span>留言板</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-zhaopian_1"></use></svg> <span>相册集</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/MyFavoriteBaby/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xingsu"></use></svg> <span>大陆养虾</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/social/link/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_shu"></use></svg> <span>加入友链</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span>个人</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/personal/essay/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_qizhi"></use></svg> <span>说说</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/personal/task_list/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_xiaoya"></use></svg> <span>清单</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/personal/equipment/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_xigua"></use></svg> <span>装备</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/personal/about/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangsu_aixin"></use></svg> <span>关于</span></a></li></ul></div></div><span class="sidebar-menu-item-title">标签</span><div class="card-tags"><div class="item-headline"></div><div class="card-tag-cloud"><a href="/tags/Arduino/" style="font-size:.88rem;color:#c1b22b">Arduino<sup>1</sup></a><a href="/tags/ESP32/" style="font-size:.88rem;color:#92b15c">ESP32<sup>1</sup></a><a href="/tags/Markdown/" style="font-size:.88rem;color:#a8369c">Markdown<sup>1</sup></a><a href="/tags/SLAM/" style="font-size:.88rem;color:#8d6e37">SLAM<sup>1</sup></a><a href="/tags/linux/" style="font-size:.88rem;color:#6a4fc3">linux<sup>1</sup></a><a href="/tags/lvgl/" style="font-size:.88rem;color:#027428">lvgl<sup>1</sup></a><a href="/tags/pyqt5/" style="font-size:.88rem;color:#c42e7e">pyqt5<sup>5</sup></a><a href="/tags/ros/" style="font-size:.88rem;color:#766266">ros<sup>21</sup></a><a href="/tags/wsl/" style="font-size:.88rem;color:#4e522c">wsl<sup>1</sup></a><a href="/tags/yolo/" style="font-size:.88rem;color:#6c1688">yolo<sup>1</sup></a><a href="/tags/%E4%BA%8B%E4%BB%B6%E7%9B%B8%E6%9C%BA/" style="font-size:.88rem;color:#100984">事件相机<sup>1</sup></a><a href="/tags/%E4%BB%BF%E7%9C%9F/" style="font-size:.88rem;color:#5d128b">仿真<sup>1</sup></a><a href="/tags/%E5%A4%96%E6%8C%82%E6%A0%87%E7%AD%BE/" style="font-size:.88rem;color:#01584a">外挂标签<sup>1</sup></a><a href="/tags/%E6%97%A0%E4%BA%BA%E6%9C%BA/" style="font-size:.88rem;color:#4dac89">无人机<sup>9</sup></a><a href="/tags/%E6%B5%8B%E8%AF%84/" style="font-size:.88rem;color:#861e41">测评<sup>1</sup></a><a href="/tags/%E7%AE%97%E6%B3%95/" style="font-size:.88rem;color:#a39674">算法<sup>3</sup></a><a href="/tags/%E9%97%AE%E9%A2%98%E5%A4%A7%E5%85%A8/" style="font-size:.88rem;color:#3d7831">问题大全<sup>1</sup></a><a href="/tags/%E9%A1%B9%E7%9B%AE%E5%88%86%E4%BA%AB/" style="font-size:.88rem;color:#0a35ad">项目分享<sup>1</sup></a></div></div><hr></div></div><div id="keyboard-tips"><div class="keyboardTitle">博客快捷键</div><div class="keybordList"><div class="keybordItem"><div class="keyGroup"><div class="key">shift K</div></div><div class="keyContent"><div class="content">关闭快捷键功能</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift A</div></div><div class="keyContent"><div class="content">打开/关闭中控台</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift M</div></div><div class="keyContent"><div class="content">播放/暂停音乐</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift D</div></div><div class="keyContent"><div class="content">深色/浅色显示模式</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift S</div></div><div class="keyContent"><div class="content">站内搜索</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift R</div></div><div class="keyContent"><div class="content">随机访问</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift H</div></div><div class="keyContent"><div class="content">返回首页</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift F</div></div><div class="keyContent"><div class="content">友链鱼塘</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift L</div></div><div class="keyContent"><div class="content">友链页面</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift P</div></div><div class="keyContent"><div class="content">关于本站</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift I</div></div><div class="keyContent"><div class="content">原版/本站右键菜单</div></div></div></div></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="anzhiyufont anzhiyu-icon-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="anzhiyufont anzhiyu-icon-arrows-left-right"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="anzhiyufont anzhiyu-icon-gear"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="anzhiyufont anzhiyu-icon-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="anzhiyufont anzhiyu-icon-comments"></i></a><a id="switch-commentBarrage" href="javascript:anzhiyu.switchCommentBarrage();" title="开关弹幕"><i class="anzhiyufont anzhiyu-icon-danmu"></i></a><button id="go-up" type="button" title="回到顶部"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i></button></div></div><div id="nav-music"><a id="nav-music-hoverTips" onclick="anzhiyu.musicToggle()" accesskey="m">播放音乐</a><div id="console-music-bg"></div><meting-js id="572504216" server="netease" type="playlist" mutex="true" preload="none" theme="var(--anzhiyu-main)" data-lrctype="0" order="random" volume="0.7"></meting-js></div><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><button class="search-close-button"><i class="anzhiyufont anzhiyu-icon-xmark"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><hr><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="anzhiyufont anzhiyu-icon-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="anzhiyufont anzhiyu-icon-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="anzhiyufont anzhiyu-icon-arrow-rotate-right" style="font-size:1rem"></i></div><div class="rightMenu-item" id="menu-top"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i></div></div><div class="rightMenu-group rightMenu-line rightMenuPlugin"><div class="rightMenu-item" id="menu-copytext"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制选中文本</span></div><div class="rightMenu-item" id="menu-pastetext"><i class="anzhiyufont anzhiyu-icon-paste"></i><span>粘贴文本</span></div><a class="rightMenu-item" id="menu-commenttext"><i class="anzhiyufont anzhiyu-icon-comment-medical"></i><span>引用到评论</span></a><div class="rightMenu-item" id="menu-newwindow"><i class="anzhiyufont anzhiyu-icon-window-restore"></i><span>新窗口打开</span></div><div class="rightMenu-item" id="menu-copylink"><i class="anzhiyufont anzhiyu-icon-link"></i><span>复制链接地址</span></div><div class="rightMenu-item" id="menu-copyimg"><i class="anzhiyufont anzhiyu-icon-images"></i><span>复制此图片</span></div><div class="rightMenu-item" id="menu-downloadimg"><i class="anzhiyufont anzhiyu-icon-download"></i><span>下载此图片</span></div><div class="rightMenu-item" id="menu-newwindowimg"><i class="anzhiyufont anzhiyu-icon-window-restore"></i><span>新窗口打开图片</span></div><div class="rightMenu-item" id="menu-search"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i><span>站内搜索</span></div><div class="rightMenu-item" id="menu-searchBaidu"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i><span>百度搜索</span></div><div class="rightMenu-item" id="menu-music-toggle"><i class="anzhiyufont anzhiyu-icon-play"></i><span>播放音乐</span></div><div class="rightMenu-item" id="menu-music-back"><i class="anzhiyufont anzhiyu-icon-backward"></i><span>切换到上一首</span></div><div class="rightMenu-item" id="menu-music-forward"><i class="anzhiyufont anzhiyu-icon-forward"></i><span>切换到下一首</span></div><div class="rightMenu-item" id="menu-music-playlist" onclick="window.open(&quot;https://music.mgodmonkey.cn&quot;, &quot;_blank&quot;);" style="display:none"><i class="anzhiyufont anzhiyu-icon-radio"></i><span>查看所有歌曲</span></div><div class="rightMenu-item" id="menu-music-copyMusicName"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制歌名</span></div></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" id="menu-randomPost"><i class="anzhiyufont anzhiyu-icon-shuffle"></i><span>随便逛逛</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="anzhiyufont anzhiyu-icon-cube"></i><span>博客分类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="anzhiyufont anzhiyu-icon-tags"></i><span>文章标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item" id="menu-copy" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制地址</span></a><a class="rightMenu-item" id="menu-commentBarrage" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-message"></i><span class="menu-commentBarrage-text">关闭热评</span></a><a class="rightMenu-item" id="menu-darkmode" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i><span class="menu-darkmode-text">深色模式</span></a><a class="rightMenu-item" id="menu-translate" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-language"></i><span>轉為繁體</span></a></div></div><div id="rightmenu-mask"></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.cbd.int/@fancyapps/ui@5.0.28/dist/fancybox/fancybox.umd.js"></script><script src="https://cdn.cbd.int/instant.page@5.2.0/instantpage.js" type="module"></script><script src="https://cdn.cbd.int/vanilla-lazyload@17.8.5/dist/lazyload.iife.min.js"></script><script src="https://cdn.cbd.int/node-snackbar@0.1.16/dist/snackbar.min.js"></script><script>function panguFn(){"object"==typeof pangu?pangu.autoSpacingPage():getScript("https://cdn.cbd.int/pangu@4.0.7/dist/browser/pangu.min.js").then((()=>{pangu.autoSpacingPage()}))}function panguInit(){GLOBAL_CONFIG_SITE.isPost&&panguFn()}document.addEventListener("DOMContentLoaded",panguInit)</script><script>var meting_api="https://api.injahow.cn/meting/?server=:server&type=:type&id=:id&auth=:auth&r=:r"</script><canvas id="universe"></canvas><script async src="https://npm.elemecdn.com/anzhiyu-theme-static@1.0.0/dark/dark.js"></script><script>var HoldLog=console.log;console.log=function(){};let now1=new Date;queueMicrotask((()=>{const o=function(){HoldLog.apply(console,arguments)},n=new Date("03/18/2023 00:00:00");now1.setTime(now1.getTime()+250);const c=(now1-n)/1e3/60/60/24,e=["欢迎来访MGodmonkeyの世界!","心中有光万物皆是光，万物皆是迪迦！","\n        \n    ███╗   ███╗ ██████╗  ██████╗ ██████╗ ███╗   ███╗ ██████╗ ███╗   ██╗██╗  ██╗███████╗██╗   ██╗\n    ████╗ ████║██╔════╝ ██╔═══██╗██╔══██╗████╗ ████║██╔═══██╗████╗  ██║██║ ██╔╝██╔════╝╚██╗ ██╔╝\n    ██╔████╔██║██║  ███╗██║   ██║██║  ██║██╔████╔██║██║   ██║██╔██╗ ██║█████╔╝ █████╗   ╚████╔╝ \n    ██║╚██╔╝██║██║   ██║██║   ██║██║  ██║██║╚██╔╝██║██║   ██║██║╚██╗██║██╔═██╗ ██╔══╝    ╚██╔╝  \n    ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██║ ╚═╝ ██║╚██████╔╝██║ ╚████║██║  ██╗███████╗   ██║   \n    ╚═╝     ╚═╝ ╚═════╝  ╚═════╝ ╚═════╝ ╚═╝     ╚═╝ ╚═════╝ ╚═╝  ╚═══╝╚═╝  ╚═╝╚══════╝   ╚═╝    \n        \n        ","已上线",Math.floor(c),"天","©2023 By MGodmonkey 1.6.12"],t=["NCC2-036","调用前置摄像头拍照成功，识别为【小笨蛋】.","Photo captured: ","🤪"];setTimeout(o.bind(console,`\n%c${e[0]} %c ${e[1]} %c ${e[2]} %c${e[3]}%c ${e[4]}%c ${e[5]}\n\n%c ${e[6]}\n`,"color:#3b70fc","","color:#3b70fc","color:#3b70fc","","color:#3b70fc","")),setTimeout(o.bind(console,`%c ${t[0]} %c ${t[1]} %c \n${t[2]} %c\n${t[3]}\n`,"color:white; background-color:#4fd953","","",'background:url("https://npm.elemecdn.com/anzhiyu-blog@1.1.6/img/post/common/tinggge.gif") no-repeat;font-size:450%')),setTimeout(o.bind(console,"%c WELCOME %c 你好，小笨蛋.","color:white; background-color:#4f90d9","")),setTimeout(console.warn.bind(console,"%c ⚡ Powered by MGodmonkey %c 你正在访问 MGodmonkey 的博客.","color:white; background-color:#f0ad4e","")),setTimeout(o.bind(console,"%c W23-12 %c 你已打开控制台.","color:white; background-color:#4f90d9","")),setTimeout(console.warn.bind(console,"%c S013-782 %c 你现在正处于监控中.","color:white; background-color:#d9534f",""))}))</script><script async src="/anzhiyu/random.js"></script><script async>!function(){var t,e,n,r,a,o,i,l,h=new Date("03/18/2023 00:00:00"),u=new Date("02/13/2024 11:47:00"),g=new Date;setInterval((()=>{!function(){g=new Date,g.getHours();var f=(g-h)/1e3/60/60/24;t=Math.floor(f);var s=(g-h)/1e3/60/60-24*t;e=Math.floor(s),1==String(e).length&&(e="0"+e);var c=(g-h)/1e3/60-1440*t-60*e;n=Math.floor(c),1==String(n).length&&(n="0"+n);var d=(g-h)/1e3-86400*t-3600*e-60*n;r=Math.round(d),1==String(r).length&&(r="0"+r),g.getHours();var m=(g-u)/1e3/60/60/24;a=Math.floor(m);var v=(g-u)/1e3/60/60-24*a;o=Math.floor(v),1==String(o).length&&(o="0"+o);var y=(g-u)/1e3/60-1440*a-60*o;i=Math.floor(y),1==String(i).length&&(i="0"+i);var M=(g-u)/1e3-86400*a-3600*o-60*i;l=Math.round(M),1==String(l).length&&(l="0"+l)}(),function(){if(!document.getElementById("footer"))return;let h="";h=`恋爱进度条运行了 ${a} 天<span id='runtime'> ${o} 小时 ${i} 分 ${l} 秒 </span><i class='anzhiyufont anzhiyu-icon-heartbeat' style='color:pink'></i><br>本站居然运行了 ${t} 天<span id='runtime'> ${e} 小时 ${n} 分 ${r} 秒 </span><i class='anzhiyufont anzhiyu-icon-heartbeat' style='color:blue'></i>`,document.getElementById("runtimeTextTip")&&(document.getElementById("runtimeTextTip").innerHTML=h)}()}),1e3)}()</script><script src="https://cdn.cbd.int/algoliasearch@4.18.0/dist/algoliasearch-lite.umd.js"></script><script src="https://cdn.cbd.int/instantsearch.js@4.60.0/dist/instantsearch.production.min.js"></script><script src="/js/search/algolia.js"></script><div class="js-pjax"><script>(()=>{const o=()=>{"object"==typeof twikoo?setTimeout(t,0):getScript("https://cdn.cbd.int/twikoo@1.6.30/dist/twikoo.all.min.js").then(t)},t=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://twikoo.mgodmonkey.cn/",region:"",onCommentLoaded:()=>{anzhiyu.loadLightbox(document.querySelectorAll("#twikoo .tk-content img:not(.tk-owo-emotion)"))}},null))};anzhiyu.loadComment(document.getElementById("twikoo-wrap"),o)})()</script><input type="hidden" name="page-type" id="page-type" value="post"><script async src="/js/anzhiyu/comment_barrage.js"></script></div><script>window.addEventListener("load",(()=>{const e=e=>{let t="";if(e.length)for(let n=0;n<e.length;n++){t+="<div class='aside-list-item'>";{const a="data-lazy-src";t+=`<a href='${e[n].url}' class='thumbnail'><img ${a}='${e[n].avatar}' alt='${e[n].nick}'><div class='name'><span>${e[n].nick} </span></div></a>`}t+=`<div class='content'>\n        <a class='comment' href='${e[n].url}' title='${e[n].content}'>${e[n].content}</a>\n        <time datetime="${e[n].date}">${anzhiyu.diffDate(e[n].date,!0)}</time></div>\n        </div>`}else t+="没有评论";let n=document.querySelector("#card-newest-comments .aside-list");n&&(n.innerHTML=t),window.lazyLoadInstance&&window.lazyLoadInstance.update(),window.pjax&&window.pjax.refresh(n)},t=()=>{if(document.querySelector("#card-newest-comments .aside-list")){const t=saveToLocal.get("twikoo-newest-comments");t?e(JSON.parse(t)):(()=>{const t=()=>{twikoo.getRecentComments({envId:"https://twikoo.mgodmonkey.cn/",region:"",pageSize:6,includeReply:!0}).then((function(t){const n=t.map((e=>{return{content:(t=e.comment,""===t||(t=(t=(t=(t=t.replace(/<img.*?src="(.*?)"?[^\>]+>/gi,"[图片]")).replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,"[链接]")).replace(/<pre><code>.*?<\/pre>/gi,"[代码]")).replace(/<[^>]+>/g,"")).length>150&&(t=t.substring(0,150)+"..."),t),avatar:e.avatar,nick:e.nick,url:e.url+"#"+e.id,date:new Date(e.created).toISOString()};var t}));saveToLocal.set("twikoo-newest-comments",JSON.stringify(n),10/1440),e(n)})).catch((function(e){document.querySelector("#card-newest-comments .aside-list").textContent="无法获取评论，请确认相关配置是否正确"}))};"object"==typeof twikoo?t():getScript("https://cdn.cbd.int/twikoo@1.6.30/dist/twikoo.all.min.js").then(t)})()}};t(),document.addEventListener("pjax:complete",t)}))</script><script async data-pjax src="https://npm.elemecdn.com/anzhiyu-theme-static@1.0.1/bubble/bubble.js"></script><script>var visitorMail="who@qq.com"</script><script async data-pjax src="https://cdn.cbd.int/anzhiyu-theme-static@1.0.0/waterfall/waterfall.js"></script><script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/qrcodejs/1.0.0/qrcode.min.js"></script><script src="/js/anzhiyu/right_click_menu.js"></script><link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-theme-static@1.1.9/icon/ali_iconfont_css.css"><script async src="https://at.alicdn.com/t/c/font_3960079_reowwynqtt7.js"></script><script async data-pjax src="/js/owo.js"></script><link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-theme-static@1.0.0/aplayer/APlayer.min.css" media="print" onload='this.media="all"'><script src="https://cdn.cbd.int/anzhiyu-blog-static@1.0.1/js/APlayer.min.js"></script><script src="https://npm.elemecdn.com/hexo-anzhiyu-music@1.0.2/assets/js/Meting2.min.js"></script><script src="https://lib.baomitu.com/pjax/0.2.8/pjax.min.js"></script><script>let pjaxSelectors=['meta[property="og:image"]','meta[property="og:title"]','meta[property="og:url"]','meta[property="og:type"]','meta[property="og:site_name"]','meta[property="og:description"]',"head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(anzhiyu.removeGlobalFnEvent("pjax"),anzhiyu.removeGlobalFnEvent("themeChange"),document.getElementById("rightside").classList.remove("rightside-show"),window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode")})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)})),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll()})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404.html")}))</script><script charset="UTF-8" src="https://cdn.cbd.int/anzhiyu-theme-static@1.1.5/accesskey/accesskey.js"></script></div><div id="popup-window"><div class="popup-window-title">通知</div><div class="popup-window-divider"></div><div class="popup-window-content"><div class="popup-tip">你好呀</div><div class="popup-link"><i class="anzhiyufont anzhiyu-icon-arrow-circle-right"></i></div></div></div><script data-pjax>function butterfly_swiper_injector_config(){var t=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),t.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/2013454d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_24.webp?_r_=29c82da3-de4f-1818-c6d4-8e86dc8f65bb" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-03-18</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/2013454d.html&quot;);" href="javascript:void(0);" alt="">Markdown语法与外挂标签写法汇总</a><div class="blog-slider__text">🥧本文汇总Markdown格式以及外挂标签在网页端的渲染效果，可作为文档进行查询</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/2013454d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/934e71d1.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_31.webp?_r_=c21fe602-3554-f265-0e73-1524950a0e28" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-06-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/934e71d1.html&quot;);" href="javascript:void(0);" alt="">物体路径规划项目笔记</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/934e71d1.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/232d6cf1.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://bu.dusays.com/2023/10/02/651ad2e1606f4.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-06-23</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/232d6cf1.html&quot;);" href="javascript:void(0);" alt="">ROS资源汇总</a><div class="blog-slider__text">ROS常用资源汇总（从入门到入坟）</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/232d6cf1.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/f1cb77fb.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" onerror="this.onerror=null,this.src=&quot;/img/404.jpg&quot;" data-lazy-src="https://mybog.s3.bitiful.net/imgs/cover/cover_11.webp?_r_=c22c6364-0c20-490e-844b-7addff113b3b" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-06-29</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/f1cb77fb.html&quot;);" href="javascript:void(0);" alt="">ROS指令大全</a><div class="blog-slider__text">ROS常用指令大全（从入门到入坟）</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/f1cb77fb.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>')}for(var elist="undefined".split(","),cpage=location.pathname,epage="/",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper_init.js"></script></body></html>